<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/testTpl1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>TestPage</title>
    <!-- InstanceEndEditable -->
    <!-- InstanceBeginEditable name="head" -->
    <!-- InstanceEndEditable -->
    <link rel="stylesheet" type="text/css" href="../style/google/KitchenSink.css">
    <!-- InstanceBeginEditable name="additionalStyle" -->
    <!-- InstanceEndEditable -->

    <script type="text/javascript">
    var djConfig = {
        isDebug: true
        ,debugAtAllCosts: true
    };
    </script>

    <script type="text/javascript" src="../../../trimpath/template-1.0.38.js"></script>
    <script type="text/javascript" src="../../../dojo/deploy/dojo.js"></script>
    <script type="text/javascript" src="../../../dojo-lotex/dojo-lotex.js"></script>
    <script type="text/javascript" src="../../velcro.js"></script>

    <!-- InstanceBeginEditable name="dojoRequire" -->

    <script type="text/javascript">
    dojo.require("lotex.util.Tree");
    dojo.require("lotex.io");
    dojo.require("lotex.string");
    dojo.require("velcro.item");

    dojo.hostenv.writeIncludes();
    </script>

    <!-- InstanceEndEditable -->
    <!-- InstanceBeginEditable name="headScript" -->

    <script type="text/javascript">
    var tree;

    var kw = {
        url: velcroConfig["selectItemFile"],
        sync: true,
        mimetype: "text/plain",
        load: function(type, data, evt) {
            tree = lotex.util.TreeFilePaser(data);
            dojo.debug(tree);
            tree.forEach(function(node){
                var item = dojo.string.trim(node.getValue());
                if(lotex.string.isBlank(item)) return;
                d("创建新选择项类型:" + item);
                var selItemType = new velcro.item.SelectItemType(item);
                var selItemTypeId = selItemType.save();
                d("创建成功，返回Id: ", selItemTypeId);

                node.forEach(function(node){
                    var item = dojo.string.trim(node.getValue());
                    if(lotex.string.isBlank(item)) return;
                    d("添加选择项:" + item);
                    d("pid: ",selItemTypeId);
                    var selItem = new velcro.item.SelectItem(item);
                    selItem.setPid(selItemTypeId);
                    var selItemId = selItem.save();
                    d("创建成功，返回Id: ", selItemId);

                    node.forEach(function(node){
                        var item = dojo.string.trim(node.getValue());
                        if(lotex.string.isBlank(item)) return;
                        d("添加选择项项目:" + item);

                        var selItemNode = new velcro.item.SelectItemNode(item);
                        var desc = node.haveChildren() ?
                            dojo.string.trim(node.getChildren()[0].getValue()) : '';

                        selItemNode.setTypeid(selItemId);
                        selItemNode.setDesc(desc);
                        var selItemNodeId = selItemNode.save(true);
                        d("创建成功，返回Id: ", selItemNodeId);
                    });
                });

            });
        },
        error: function(t, e) {
            alert("Error!");
            dd(t, e);
        }
    };
    dojo.io.bind(kw);

    </script>

    <!-- InstanceEndEditable -->
</head>
<body>
    <table style="width: 100%" cellspacing="0" cellpadding="0">
        <tbody>
            <tr>
                <td style="vertical-align: top" align="left">
                    <div class="ks-Info">
                        Testpage</div>
                </td>
            </tr>
            <tr>
                <td style="vertical-align: top" align="left">
                    <table class="ks-Sink" cellspacing="0" cellpadding="0">
                        <tbody>
                            <tr>
                                <td style="vertical-align: top; width: 100%; height: 100%" align="left">
                                    <div id="container">
                                        <!-- InstanceBeginEditable name="htmlContainer" -->
                                        <!-- InstanceEndEditable -->
                                    </div>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
    <fieldset>
        <legend>Output</legend>
        <div id="debug.output">
        </div>
    </fieldset>
</body>
<!-- InstanceEnd --></html>
